package diploma.kisel.modelas.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.JTable;

import diploma.kisel.modelas.domain.Application;
import diploma.kisel.modelas.domain.Computer;
import diploma.kisel.modelas.domain.Concept;
import diploma.kisel.modelas.domain.Database;
import diploma.kisel.modelas.domain.DatabaseType;
import diploma.kisel.modelas.domain.Device;
import diploma.kisel.modelas.domain.Program;
import diploma.kisel.modelas.domain.UserType;
import diploma.kisel.modelas.domain.Workplace;
import diploma.kisel.modelas.domain.Workstation;
import diploma.kisel.modelas.domain.WorkstationType;
import diploma.kisel.modelas.gui.common.CurrentVar;
import diploma.kisel.modelas.gui.common.TablesService;
import diploma.kisel.modelas.gui.common.TablesSettings;
import diploma.kisel.modelas.service.ApplicationServiceImpl;
import diploma.kisel.modelas.service.ConceptServiceImpl;
import diploma.kisel.modelas.service.DatabaseServiceImpl;
import diploma.kisel.modelas.service.StaticHelper;
import diploma.kisel.modelas.service.WorkplaceServiceImpl;
import diploma.kisel.modelas.service.WorkstationServiceImpl;
import diploma.kisel.modelas.service.api.ApplicationService;
import diploma.kisel.modelas.service.api.ConceptService;
import diploma.kisel.modelas.service.api.DatabaseService;
import diploma.kisel.modelas.service.api.WorkplaceService;
import diploma.kisel.modelas.service.api.WorkstationService;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * This window is used to create new workplace.
 * 
 * @author Nikolay Kisel
 *
 */
public class WorkplaceWindow extends JFrame {

	private JTextArea textArea;
	private JRadioButton rdbtnUsers;
	private JRadioButton rdbtnPersonal;
	private JRadioButton rdbtnOne;
	private JRadioButton rdbtnTwo;

	private JPanel contentPane;
	private JTable tablePC;
	private JTable tableDevice;
	private JTable tableProgram;
	private JTable tableApplication;
	private JTable tableDatabase;
	
	private int rowDevice;
	private int rowDatabase;

	private static DefaultTableModel model;
	private Set<Computer> computers = new HashSet<Computer>();
	private Set<Device> devices = new HashSet<Device>();
	private Set<Program> programs = new HashSet<Program>();
	private Set<Application> applications = new HashSet<Application>();
	private Set<Database> databases = new HashSet<Database>();

	private ApplicationService applicationService = new ApplicationServiceImpl();
	private WorkplaceService workplaceService = new WorkplaceServiceImpl();
	private WorkstationService workstationService = new WorkstationServiceImpl();
	private DatabaseService databaseService = new DatabaseServiceImpl();

	// ******************need to change*********************************
	private ConceptService conceptService = new ConceptServiceImpl();

	// private Concept currConcept = conceptService.findById(1);

	// *****************************************************************
	private Concept currConcept = CurrentVar.getCurrentConcept();
	private static WorkplaceWindow frame;

	/**
	 * Create the frame.
	 */
	public WorkplaceWindow() {
		setTitle("Рабочее место");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 511, 545);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);

		JLabel label = new JLabel("Названия:");
		sl_contentPane.putConstraint(SpringLayout.NORTH, label, 10,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, label, 10,
				SpringLayout.WEST, contentPane);
		contentPane.add(label);

		JScrollPane scrollPane = new JScrollPane();
		sl_contentPane.putConstraint(SpringLayout.NORTH, scrollPane, 10,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, scrollPane, 6,
				SpringLayout.EAST, label);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, scrollPane, 61,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, scrollPane, 132,
				SpringLayout.EAST, label);
		contentPane.add(scrollPane);

		textArea = new JTextArea();
		scrollPane.setViewportView(textArea);

		rdbtnUsers = new JRadioButton("Пользователи");
		rdbtnUsers.setSelected(true);
		sl_contentPane.putConstraint(SpringLayout.NORTH, rdbtnUsers, 10,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnUsers, 25,
				SpringLayout.EAST, scrollPane);
		contentPane.add(rdbtnUsers);

		rdbtnPersonal = new JRadioButton("Персоанал");
		sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnPersonal, 0,
				SpringLayout.WEST, rdbtnUsers);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, rdbtnPersonal, 0,
				SpringLayout.SOUTH, scrollPane);
		contentPane.add(rdbtnPersonal);

		ButtonGroup butGroupUserType = new ButtonGroup();
		butGroupUserType.add(rdbtnPersonal);
		butGroupUserType.add(rdbtnUsers);

		rdbtnOne = new JRadioButton("1 смена");
		rdbtnOne.setSelected(true);
		sl_contentPane.putConstraint(SpringLayout.NORTH, rdbtnOne, 0,
				SpringLayout.NORTH, rdbtnUsers);
		sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnOne, 41,
				SpringLayout.EAST, rdbtnUsers);
		contentPane.add(rdbtnOne);

		rdbtnTwo = new JRadioButton("2 смены");
		sl_contentPane.putConstraint(SpringLayout.NORTH, rdbtnTwo, 0,
				SpringLayout.NORTH, rdbtnPersonal);
		sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnTwo, 0,
				SpringLayout.WEST, rdbtnOne);
		contentPane.add(rdbtnTwo);

		ButtonGroup butGroupShift = new ButtonGroup();
		butGroupShift.add(rdbtnOne);
		butGroupShift.add(rdbtnTwo);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		sl_contentPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6,
				SpringLayout.SOUTH, scrollPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, tabbedPane, 5,
				SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, tabbedPane, 382,
				SpringLayout.SOUTH, scrollPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, tabbedPane, 5,
				SpringLayout.EAST, contentPane);
		contentPane.add(tabbedPane);

		JPanel panelTO = new JPanel();
		tabbedPane.addTab("ТО", null, panelTO, null);
		SpringLayout sl_panelTO = new SpringLayout();
		panelTO.setLayout(sl_panelTO);

		JLabel label_1 = new JLabel("Определить ПЭВМ:");
		sl_panelTO.putConstraint(SpringLayout.WEST, label_1, 10,
				SpringLayout.WEST, panelTO);
		panelTO.add(label_1);

		JButton buttonAddPC = new JButton("Определить");
		buttonAddPC.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addPC();
			}
		});
		sl_panelTO.putConstraint(SpringLayout.NORTH, buttonAddPC, 10,
				SpringLayout.NORTH, panelTO);
		sl_panelTO.putConstraint(SpringLayout.WEST, buttonAddPC, 48,
				SpringLayout.EAST, label_1);
		sl_panelTO.putConstraint(SpringLayout.NORTH, label_1, 4,
				SpringLayout.NORTH, buttonAddPC);
		panelTO.add(buttonAddPC);

		JScrollPane scrollPane_1 = new JScrollPane();
		sl_panelTO.putConstraint(SpringLayout.NORTH, scrollPane_1, 12,
				SpringLayout.SOUTH, buttonAddPC);
		sl_panelTO.putConstraint(SpringLayout.WEST, scrollPane_1, 0,
				SpringLayout.WEST, panelTO);
		sl_panelTO.putConstraint(SpringLayout.SOUTH, scrollPane_1, 85,
				SpringLayout.SOUTH, buttonAddPC);
		sl_panelTO.putConstraint(SpringLayout.EAST, scrollPane_1, 480,
				SpringLayout.WEST, panelTO);
		panelTO.add(scrollPane_1);

		tablePC = new JTable(TablesSettings.modelSettingForPC(model, computers));
		scrollPane_1.setViewportView(tablePC);
		TablesSettings.makeFirstColumnInvisible(tablePC);

		JLabel label_2 = new JLabel("Добавить устройство:");
		sl_panelTO.putConstraint(SpringLayout.NORTH, label_2, 35, SpringLayout.SOUTH, scrollPane_1);
		sl_panelTO.putConstraint(SpringLayout.WEST, label_2, 0,
				SpringLayout.WEST, label_1);
		panelTO.add(label_2);

		JButton buttonAddDevice = new JButton("Добавить");
		buttonAddDevice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addDevice();
			}
		});
		sl_panelTO.putConstraint(SpringLayout.NORTH, buttonAddDevice, -4,
				SpringLayout.NORTH, label_2);
		sl_panelTO.putConstraint(SpringLayout.WEST, buttonAddDevice, 0,
				SpringLayout.WEST, buttonAddPC);
		panelTO.add(buttonAddDevice);

		JScrollPane scrollPane_2 = new JScrollPane();
		sl_panelTO.putConstraint(SpringLayout.NORTH, scrollPane_2, 12,
				SpringLayout.SOUTH, buttonAddDevice);
		sl_panelTO.putConstraint(SpringLayout.WEST, scrollPane_2, 0, SpringLayout.WEST, panelTO);
		sl_panelTO.putConstraint(SpringLayout.SOUTH, scrollPane_2, 139,
				SpringLayout.SOUTH, buttonAddDevice);
		sl_panelTO.putConstraint(SpringLayout.EAST, scrollPane_2, 0, SpringLayout.EAST, panelTO);
		panelTO.add(scrollPane_2);

		tableDevice = new JTable(TablesSettings.modelSettingForDevice(model,
				devices));
		scrollPane_2.setViewportView(tableDevice);
		TablesSettings.makeFirstColumnInvisible(tableDevice);
		
		tableDevice.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					if (rowDevice >= 0) {
						int response = JOptionPane.showConfirmDialog(frame,
								"Удалить выделенную строку?");

						if (response == JOptionPane.YES_OPTION) {
							Device device = TablesService.getDeviceFromTable(
									tableDevice, rowDevice);
							devices.remove(device);
							rowDevice = -1;
							updateModelForDevice();
						}
					}
				}
			}
		});

		ListSelectionModel listSelModDevice = tableDevice.getSelectionModel();
		listSelModDevice.addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent e) {
				rowDevice = tableDevice.getSelectedRow();
			}
		});

		JPanel panelPO = new JPanel();
		tabbedPane.addTab("ПО", null, panelPO, null);
		SpringLayout sl_panelPO = new SpringLayout();
		panelPO.setLayout(sl_panelPO);

		JLabel label_3 = new JLabel("Добавить программу:");
		sl_panelPO.putConstraint(SpringLayout.WEST, label_3, 10,
				SpringLayout.WEST, panelPO);
		panelPO.add(label_3);

		JButton btnAddProgram = new JButton("Добавить");
		btnAddProgram.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addProgram();
			}
		});
		sl_panelPO.putConstraint(SpringLayout.NORTH, btnAddProgram, 10,
				SpringLayout.NORTH, panelPO);
		sl_panelPO.putConstraint(SpringLayout.WEST, btnAddProgram, 37,
				SpringLayout.EAST, label_3);
		sl_panelPO.putConstraint(SpringLayout.NORTH, label_3, 4,
				SpringLayout.NORTH, btnAddProgram);
		panelPO.add(btnAddProgram);

		JScrollPane scrollPane_3 = new JScrollPane();
		sl_panelPO.putConstraint(SpringLayout.NORTH, scrollPane_3, 6,
				SpringLayout.SOUTH, btnAddProgram);
		sl_panelPO.putConstraint(SpringLayout.WEST, scrollPane_3, 0, SpringLayout.WEST, panelPO);
		sl_panelPO.putConstraint(SpringLayout.SOUTH, scrollPane_3, 121,
				SpringLayout.SOUTH, btnAddProgram);
		sl_panelPO.putConstraint(SpringLayout.EAST, scrollPane_3, 0, SpringLayout.EAST, panelPO);
		panelPO.add(scrollPane_3);

		tableProgram = new JTable(TablesSettings.modelSettingForProgram(model,
				programs));
		scrollPane_3.setViewportView(tableProgram);
		TablesSettings.makeFirstColumnInvisible(tableProgram);

		JLabel label_4 = new JLabel("Добавить приложение:");
		sl_panelPO.putConstraint(SpringLayout.NORTH, label_4, 22, SpringLayout.SOUTH, scrollPane_3);
		sl_panelPO.putConstraint(SpringLayout.WEST, label_4, 10,
				SpringLayout.WEST, panelPO);
		panelPO.add(label_4);

		JButton buttonAddApplication = new JButton("Добавить");
		buttonAddApplication.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addApplication();
			}
		});
		sl_panelPO.putConstraint(SpringLayout.NORTH, buttonAddApplication, -4,
				SpringLayout.NORTH, label_4);
		sl_panelPO.putConstraint(SpringLayout.WEST, buttonAddApplication, 0,
				SpringLayout.WEST, btnAddProgram);
		panelPO.add(buttonAddApplication);

		JScrollPane scrollPane_4 = new JScrollPane();
		sl_panelPO.putConstraint(SpringLayout.NORTH, scrollPane_4, 6,
				SpringLayout.SOUTH, buttonAddApplication);
		sl_panelPO.putConstraint(SpringLayout.WEST, scrollPane_4, 0, SpringLayout.WEST, panelPO);
		sl_panelPO.putConstraint(SpringLayout.SOUTH, scrollPane_4, -23,
				SpringLayout.SOUTH, panelPO);
		sl_panelPO.putConstraint(SpringLayout.EAST, scrollPane_4, 0, SpringLayout.EAST, panelPO);
		panelPO.add(scrollPane_4);

		tableApplication = new JTable(
				TablesSettings.modelSettingForApplication(model, applications));
		scrollPane_4.setViewportView(tableApplication);
		TablesSettings.makeFirstColumnInvisible(tableApplication);

		JPanel panelIO = new JPanel();
		tabbedPane.addTab("ИО", null, panelIO, null);
		SpringLayout sl_panelIO = new SpringLayout();
		panelIO.setLayout(sl_panelIO);

		JLabel label_5 = new JLabel("Добавить локальную БД:");
		sl_panelIO.putConstraint(SpringLayout.NORTH, label_5, 18,
				SpringLayout.NORTH, panelIO);
		sl_panelIO.putConstraint(SpringLayout.WEST, label_5, 10,
				SpringLayout.WEST, panelIO);
		panelIO.add(label_5);

		JButton buttonAddDB = new JButton("Добавить ");
		buttonAddDB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addDatabase();
			}
		});
		sl_panelIO.putConstraint(SpringLayout.NORTH, buttonAddDB, -4,
				SpringLayout.NORTH, label_5);
		sl_panelIO.putConstraint(SpringLayout.WEST, buttonAddDB, 47,
				SpringLayout.EAST, label_5);
		panelIO.add(buttonAddDB);

		JScrollPane scrollPane_5 = new JScrollPane();
		sl_panelIO.putConstraint(SpringLayout.NORTH, scrollPane_5, 4,
				SpringLayout.SOUTH, buttonAddDB);
		sl_panelIO.putConstraint(SpringLayout.WEST, scrollPane_5, 0,
				SpringLayout.WEST, panelIO);
		sl_panelIO.putConstraint(SpringLayout.SOUTH, scrollPane_5, -147,
				SpringLayout.SOUTH, panelIO);
		sl_panelIO.putConstraint(SpringLayout.EAST, scrollPane_5, 480,
				SpringLayout.WEST, panelIO);
		panelIO.add(scrollPane_5);

		tableDatabase = new JTable(TablesSettings.modelSettingForDatabase(
				model, databases));
		scrollPane_5.setViewportView(tableDatabase);
		TablesSettings.makeFirstColumnInvisible(tableDatabase);
		
		tableDatabase.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					if (rowDatabase >= 0) {
						int response = JOptionPane.showConfirmDialog(frame,
								"Удалить выделенную строку?");

						if (response == JOptionPane.YES_OPTION) {
							Database database = TablesService.getDatabaseFromTable(
									tableDatabase, rowDatabase);
							databases.remove(database);
							rowDatabase = -1;
							updateModelForDatabase();
						}
					}
				}
			}
		});

		ListSelectionModel listSelModDatabase = tableDatabase.getSelectionModel();
		listSelModDatabase.addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent e) {
				rowDatabase = tableDatabase.getSelectedRow();
			}
		});

		JButton buttonCancel = new JButton("Отмена");
		buttonCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
			}
		});
		sl_contentPane.putConstraint(SpringLayout.SOUTH, buttonCancel, 0, SpringLayout.SOUTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, buttonCancel, 0, SpringLayout.EAST, contentPane);
		contentPane.add(buttonCancel);

		JButton buttonSave = new JButton("Сохранить ");
		sl_contentPane.putConstraint(SpringLayout.NORTH, buttonSave, 0, SpringLayout.NORTH, buttonCancel);
		sl_contentPane.putConstraint(SpringLayout.EAST, buttonSave, -6, SpringLayout.WEST, buttonCancel);
		buttonSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				saveWorkplace();
			}
		});
		contentPane.add(buttonSave);
	}

	public void addPC() {
		ComputerCatalogWindow computerCatalogWindow = new ComputerCatalogWindow();
		ComputerCatalogWindow.setFrame(computerCatalogWindow);
		computerCatalogWindow.setFromWorkpalceWindow(true);
		computerCatalogWindow.setCurrWorkplaceWindow(this);
		computerCatalogWindow.setVisible(true);
	}

	public void addDevice() {
		DeviceCatalogWindow deviceCatalogWindow = new DeviceCatalogWindow();
		DeviceCatalogWindow.setFrame(deviceCatalogWindow);
		deviceCatalogWindow.setFromWorkplaceWindow(true);
		deviceCatalogWindow.setCurrWorkplaceWindow(this);
		deviceCatalogWindow.setVisible(true);
	}

	public void addProgram() {
		ProgramCatalogWindow programCatalogWindow = new ProgramCatalogWindow();
		ProgramCatalogWindow.setFrame(programCatalogWindow);
		programCatalogWindow.setFromWorkpalceWindow(true);
		programCatalogWindow.setCurrWorkplaceWindow(this);
		programCatalogWindow.getButtonAdd().setVisible(false);
		programCatalogWindow.setVisible(true);
	}

	public void addApplication() {
		ApplicationWindow applicationWindow = new ApplicationWindow();
		ApplicationWindow.setFrame(applicationWindow);
		applicationWindow.setCurrWorkplaceWindow(this);
		applicationWindow.setVisible(true);
	}

	public void addDatabase() {
		DatabaseWindow databaseWindow = new DatabaseWindow();
		DatabaseWindow.setFrame(databaseWindow);
		databaseWindow.setCurrentWorkplaceWindow(this);
		databaseWindow.setVisible(true);
	}

	public void setNewModelForPC(Computer computer) {
		computers = new HashSet<Computer>();
		computers.add(computer);
		tablePC.setModel(TablesSettings.modelSettingForPC(model, computers));
		TablesSettings.makeFirstColumnInvisible(tablePC);
	}

	public void setNewModelForDevice(Device device) {
		devices.add(device);
		updateModelForDevice();
	}
	
	public void updateModelForDevice() {
		tableDevice.setModel(TablesSettings.modelSettingForDevice(model,
				devices));
		TablesSettings.makeFirstColumnInvisible(tableDevice);
	}

	public void setNewModelForDatabase(Database database) {
		databases.add(database);
		updateModelForDatabase();
	}
	
	public void updateModelForDatabase() {
		tableDatabase.setModel(TablesSettings.modelSettingForDatabase(model,
				databases));
		TablesSettings.makeFirstColumnInvisible(tableDatabase);
	}

	public void setNewModelForProgram(Program program) {
		programs.add(program);
		tableProgram.setModel(TablesSettings.modelSettingForProgram(model,
				programs));
		TablesSettings.makeFirstColumnInvisible(tableProgram);
	}

	public void setNewModelForApplication(Application application) {
		applications.add(application);
		tableApplication.setModel(TablesSettings.modelSettingForApplication(
				model, applications));
		TablesSettings.makeFirstColumnInvisible(tableApplication);
	}

	public void saveWorkplace() {
		String text = textArea.getText();
		String[] names = StaticHelper.getWords(text, ",");
		List<Workplace> workplaces = new ArrayList<>();
		int countOfShift = 0;
		if (rdbtnOne.isSelected())
			countOfShift = 1;
		else
			countOfShift = 2;
		// save applications
		for (Application application : applications) {
			applicationService.save(application);
		}
		//save database
		for (Database database : databases) {
			database.setType(DatabaseType.Local);
			databaseService.save(database);
		}
		UserType userType = UserType.Other;
		WorkstationType workstationType = WorkstationType.User;
		if (rdbtnPersonal.isSelected()) {
			userType = UserType.Staff;
			workstationType = WorkstationType.Staff;
		}
		// save workplaces
		for (int i = 0; i < names.length; i++) {
			Workplace workplace = new Workplace(names[i], userType);
			workplace.setApplications(applications);
			workplace.setPrograms(programs);
			workplace.setLocalDatabases(databases);
			workplaces.add(workplace);
			workplaceService.save(workplace);
		}
		// save workstations
		for (int i = 0; i < names.length; i += countOfShift) {
			Workstation workstation = new Workstation("Ws" + names[i],
					workstationType);
			Set<Workplace> setWorkplaces = new HashSet<>();
			setWorkplaces.add(workplaces.get(i));
			if (countOfShift == 2 && i < names.length - 1)
				setWorkplaces.add(workplaces.get(i + 1));
			workstation.setWorkplaces(setWorkplaces);
			workstation.setComputers(computers);
			workstation.setDevices(devices);
			workstation.setConcept(currConcept);
			workstationService.save(workstation);
		}
		JOptionPane.showMessageDialog(frame, "Рабочие места сохранены.");
		frame.setVisible(false);
	}

	public static WorkplaceWindow getFrame() {
		return frame;
	}

	public static void setFrame(WorkplaceWindow frame) {
		WorkplaceWindow.frame = frame;
	}
}
